<template>
  <div class="app-container">
    <div class="header">
      <div class="block">
        <el-cascader
          v-model="value"
          :options="options"
          placeholder="请选择分类"
          @change="handleChange"
        />
      </div>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="序号" width="70">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="时间" width="80" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="描述" width="200" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.description }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学院" width="200" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.college }}</span>
        </template>
      </el-table-column>
      <el-table-column label="专业" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.major }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="操作" width="100">
        <template slot-scope="{row}">
          <div>
            <router-link :to="{path:'./view',query: {row}}">
              <el-button type="text">下载</el-button>
            </router-link>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import * as measure from '@/api/measure'
export default {
  data() {
    return {
      value: [],
      options: null,
      list: null,
      listLoading: false
    }
  },
  created() {
    this.getOptions()
    this.fetchData(['2021', '大数据与智能工程学院'])
  },
  methods: {
    getOptions() {
      measure.option2().then(response => {
        this.options = response.data
        console.log(this.options)
      })
    },
    fetchData(value) {
      this.listLoading = true
      measure.list2({ 'time': value[0], 'college': value[1] }).then(response => {
        this.list = response.data
        this.listLoading = false
      })
    },
    handleChange(value) {
      // console.log(value)
      this.fetchData(value)
    }
  }
}
</script>
<style scoped>
.header{
  margin-bottom: 10px;
}
</style>
